/**
 * @class Ext.app.DanhSachKhoPanel
 * @extends Ext.panel.Panel
 */
Ext.define('Ext.app.DanhSachKhoPanel', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.danhSachKhoPanel',
    autoScroll: true,
    titleAlign: 'center',
    border: true,
    layout: 'border',
    items: [
        {
            region: 'center',
            xtype: 'gridpanel',
            columnLines: true,
            viewConfig: {
                loadingText: this.translations.get("HOME.PLEASE_WAIT"),
                stripeRows: true
            },
            store: {
                fields: ['name', 'address', 'phone', 'type'],
                proxy: {
                     type: 'ajax',
                     url: 'DanhSachKho.jsp',
                     reader: {
                         type: 'json',
                         root: 'root',
                         totalProperty: 'totalCount'
                     }
                 }                
            },
            columns: [{ 
                text: this.translations.get("HOME.TEN_KHO"),
                sortable: true,
                dataIndex: 'name',
                flex: 1
            },{
                text: this.translations.get("HOME.DIA_CHI"),
                sortable: true,
                dataIndex: 'address',
                width: 200
            },{
                text: this.translations.get("HOME.PHONE"),
                sortable: true,
                dataIndex: 'phone',
                width: 100
            },{
                text: this.translations.get("HOME.PHAN_LOAI"),
                sortable: true,
                dataIndex: 'type',
                renderer: function(value) {
                    if(value == "CHINH_PHAM" || value == "THU_PHAM" || value == "PHE_PHAM") {
                        return translations.get("HOME." + value);
                    }
                    return "";
                },
                width: 150
            }],
            tbar: [
                {
                    icon: 'images/add.png',
                    handler: function(button) {
                        var wind = Ext.create('widget.taoMoiKhoWindow', {
                            title: translations.get('HOME.TAO_MOI')
                        });
                        wind.setOpener(button.up('gridpanel'));
                        wind.show();
                    }
                }
            ],
            afterFirstLayout: function() {
                // paging bar on the bottom [
                var bbar = Ext.create('Ext.PagingToolbar', {
                    store: this.getStore(),
                    beforePageText: 'Trang',
                    afterPageText: '/ {0}'
                });
                bbar.dock = "bottom";
                this.addDocked(bbar);
                //]
                this.getStore().load();
            },
            reload: function() {
                this.getStore().load();
            }
        }
    ],
    afterRender: function() {
        this.callParent(arguments);
        this.down('gridpanel').getStore().load();
    }
});
